package edu.bu.grocerylist.mock;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import edu.bu.grocerylist.dao.IGroceryListDao;
import edu.bu.grocerylist.model.GroceryList;
import edu.bu.grocerylist.model.GroceryUser;

/**
 * @author donlanp
 *
 */
public class MockGroceryListDao implements IGroceryListDao {
	
	private List<GroceryList> testData;
	
	public MockGroceryListDao(){
		testData = new ArrayList<GroceryList>();
		
		for(int i = 0; i < 10; i++){
			GroceryList list = new GroceryList("List" + i, "Test description", new Date());
			list.setGroceryListId(i);
			list.setGroceryUserId(i);
			testData.add(list);
			
		}
	}
	

	/* (non-Javadoc)
	 * @see edu.bu.grocerylist.dao.IGroceryListDao#saveGroceryList(edu.bu.grocerylist.model.GroceryList)
	 */
	public GroceryList saveGroceryList(GroceryList list) {
		list.setGroceryListId(testData.size());
		testData.add(list);
		list.setGroceryListId(testData.size() - 1);
		return list;

	}

	/* (non-Javadoc)
	 * @see edu.bu.grocerylist.dao.IGroceryListDao#deleteGroceryList(edu.bu.grocerylist.model.GroceryList)
	 */
	public boolean deleteGroceryList(GroceryList list) {
		Iterator<GroceryList> iter = testData.iterator();
		while(iter.hasNext()){
			GroceryList current = iter.next();
			if(current.getGroceryListId() == list.getGroceryListId()){
				iter.remove();
				return true;
			}
		}
		
		return false;
	}

	/* (non-Javadoc)
	 * @see edu.bu.grocerylist.dao.IGroceryListDao#getGroceryListsByUser(java.lang.String)
	 */
	public List<GroceryList> getGroceryListsByUser(int userId) {
		List<GroceryList> found = new ArrayList<GroceryList>();
		for(GroceryList l : testData){
			if(l.getGroceryUserId() == userId){
				found.add(l);				
			} 
		}
		
		return found;
	}

	/* (non-Javadoc)
	 * @see edu.bu.grocerylist.dao.IGroceryListDao#getGroceryListById(int)
	 */
	public GroceryList getGroceryListById(int id) {
		GroceryList found = null;
		for(GroceryList l : testData){
			if(l.getGroceryListId() == id){
				found = l;
			}
		}
		
		return found;
	}


	public List<GroceryList> getAllGroceryLists() {
		// TODO Auto-generated method stub
		return null;
	}


	public void deleteGroceryListsOfUser(GroceryUser user) {
		// TODO Auto-generated method stub
		
	}

}
